
use anyhow::Result;
use hyper::{Client, client::HttpConnector};

use serde::{Deserialize, Serialize};

use crate::rpc::{JsonRpcRequest, jsonrpc_request};

#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "PascalCase")]
pub struct SectorId {
    pub miner: u64,
    pub number: u64,
}

pub async fn pledge_on_sector(client: &Client<HttpConnector>, url: &str, token: &str) -> Result<SectorId>{
    let req = JsonRpcRequest::with_params("Filecoin.PledgeSector", vec![]);
    let sector = jsonrpc_request::<SectorId>(client, url, token, req).await?;
    match sector {
        None => Err(anyhow::anyhow!("pledge sector error, no sector id return.")), 
        Some(v) => Ok(v)
    }
}